

########################################

Table A4. 5-Indicators Per Factor

########################################

####################

      N=500

####################

      
library(lavaan)
library(boot)


popmodel<-'
f1 =~ 0.5*x1 + 0.424*x2 + 0.581*x3 + 0.48*x4 + 0.55*x5
f2 =~ 0.55*x6 + 0.38*x7 + 0.6*x8 + 0.85*x9 + 0.6*x10 + .65*x2
f3 =~ 0.58*x11 + .62*x12 + 0.49*x13 + 0.62*x14 + 0.64*x15 + 0.65*x10

f3 ~~ 0.408*f1 + 0.262*f2
f1 ~~ 0.173*f2

f1 ~ 0*1
f2 ~ 0*1
f3 ~ 0*1

x1~~0.549*x1
x2~~1.134*x2
x3~~0.844*x3
x4~~0.371*x4
x5~~0.446*x5
x6~~0.356*x6
x7~~0.799*x7
x8~~0.488*x8
x9~~0.566*x9
x10~~0.46*x10
x11~~0.488*x11
x12~~0.566*x12
x13~~0.5*x13
x14~~0.4*x14
x15~~0.45*x15



'

mis_model<-'  

f1 =~ x1 + x2 + x3 + x4 + x5
f2 =~ x6 + x7 + x8 + x9 + x10
f3 =~ x11 + x12 + x13 + x14 + x15
f3 ~~ f1 + f2
f1 ~~ f2



'


set.seed(500)
mydata<-simulateData(popmodel, model.type = "sem", sample.nobs=500L)
fit1 <- cfa(model = mis_model, data=mydata, meanstructure=FALSE, likelihood = "wishart", estimator = "ML")

modindices(fit1, minimum.value = 0, sort = TRUE)[1:12,]



newpar='
f3	=~	x10
f2	=~	x2
f1	=~	x10
f3	=~	x9
f3	=~	x6
f3	=~	x8
x6	~~	x10
x6	~~	x9
x10	~~	x11
x2	~~	x9
x8	~~	x14
x6	~~	x8

'


lavTestScore(fit1, add=newpar)





#####################.  Bootstrap LM Test

newpar='
f3=~x10
f2=~x2
f1=~x10
f3=~x9
f3=~x6
f3=~x8
x10~~x6
x9~~x6
x10~~x11
x2~~x9
x8~~x14
x6~~x8'



set.seed(500)

Data<-mydata


bin.1000 <- matrix(NA, nrow = 500, ncol = 2)
for (i in 1:500) {
  
  boot.idx <- sample.int(nrow(Data), replace = TRUE)
  Data.boot <- Data[boot.idx,]
  
  fit2 <- sem(model = mis_model, data = Data.boot, int.ov.free = FALSE, std.lv = FALSE, estimator = "ML")
  
  bin.1000[i, 1] <- lavTestScore(fit2, add = newpar)$uni[1, 4]
  bin.1000[i, 2] <- lavTestScore(fit2, add = newpar)$uni[1, 6]
}

t1 <- mean(bin.1000[, 1], na.rm = TRUE)
t2 <- mean(bin.1000[, 2], na.rm = TRUE)

t1
t2





############. Bootstrap Wald Test


w_model<-'  

f1 =~ x1 + x2 + x3 + x4 + x5 + b3*x10
f2 =~ x6 + x7 + x8 + x9 + x10 +b2*x2
f3 =~ x11 + x12 + x13 + x14 + x15 + b1*x10 + b4*x9 + b5*x6 + b6*x8
f3 ~~ f1 + f2
f1 ~~ f2

x10~~b7*x6
x9~~b8*x6
x10~~b9*x11
x2~~b10*x9
x8~~b11*x14
x6~~b12*x8


'


fit2 <- sem(model = w_model, data=mydata, meanstructure=FALSE, likelihood = "wishart", estimator = "ML")


con='

b1==0


'



set.seed(500)
mydata<-simulateData(popmodel, model.type = "sem", sample.nobs=500L)
Data<-mydata
# Initialize the matrix to store bootstrap results
bin.1000 <- matrix(NA, nrow = 500, ncol = 2)

# Loop through bootstrap iterations
for (i in 1:500) {
  
  # Perform one bootstrap iteration
  boot.res <- tryCatch({
    # Generate bootstrap sample
    boot.idx <- sample.int(nrow(Data), replace = TRUE)
    Data.boot <- Data[boot.idx, ]
    
    # Fit the SEM model
    fit2 <- sem(model = w_model, data = Data.boot, meanstructure = FALSE, likelihood = "wishart", estimator = "ML")
    
    # Calculate Wald test statistics and p-values
    wald_stat <- lavTestWald(fit2, constraints = con)$stat[1]
    wald_p_value <- lavTestWald(fit2, constraints = con)$p.value[1]
    
    # Return statistics
    list(stat = wald_stat, p_value = wald_p_value)
  }, error = function(e) {
    # If SEM model did not converge, return NULL
    NULL
  })
  
  # Check if boot.res is not NULL (i.e., SEM model converged)
  if (!is.null(boot.res)) {
    # Update the matrix with Wald test statistics and p-values
    bin.1000[i, 1] <- boot.res$stat
    bin.1000[i, 2] <- boot.res$p_value
  }
}

# Calculate the means of the Wald test statistics and p-values
w1 <- mean(bin.1000[, 1], na.rm = TRUE)
w2 <- mean(bin.1000[, 2], na.rm = TRUE)
w1
w2




###########################

   Likelihood Ratio Test

##########################



m_0<-'  

f1 =~ x1 + x2 + x3 + x4 + x5
f2 =~ x6 + x7 + x8 + x9 + x10
f3 =~ x11 + x12 + x13 + x14 + x15
f3 ~~ f1 + f2
f1 ~~ f2

'
lrt_0<-sem(model = m_0, data=mydata, meanstructure=FALSE, likelihood = "wishart", estimator = "ML")


m_1<-'  

f1 =~ x1 + x2 + x3 + x4 + x5
f2 =~ x6 + x7 + x8 + x9 + x10
f3 =~ x11 + x12 + x13 + x14 + x15 + x10
f3 ~~ f1 + f2
f1 ~~ f2

'
lrt_1<-sem(model = m_1, data=mydata, meanstructure=FALSE, likelihood = "wishart", estimator = "ML")

m_2<-'  

f1 =~ x1 + x2 + x3 + x4 + x5
f2 =~ x6 + x7 + x8 + x9 + x10 + x2
f3 =~ x11 + x12 + x13 + x14 + x15 + x10
f3 ~~ f1 + f2
f1 ~~ f2

'
lrt_2<-sem(model = m_2, data=mydata, meanstructure=FALSE, likelihood = "wishart", estimator = "ML")



m_3<-'  

f1 =~ x1 + x2 + x3 + x4 + x5 + x10
f2 =~ x6 + x7 + x8 + x9 + x10 + x2
f3 =~ x11 + x12 + x13 + x14 + x15 + x10
f3 ~~ f1 + f2
f1 ~~ f2

'
lrt_3<-sem(model = m_3, data=mydata, meanstructure=FALSE, likelihood = "wishart", estimator = "ML")


m_4<-'  

f1 =~ x1 + x2 + x3 + x4 + x5 + x10
f2 =~ x6 + x7 + x8 + x9 + x10 + x2
f3 =~ x11 + x12 + x13 + x14 + x15 + x10 + x9
f3 ~~ f1 + f2
f1 ~~ f2

'
lrt_4<-sem(model = m_4, data=mydata, meanstructure=FALSE, likelihood = "wishart", estimator = "ML")

m_5<-'  

f1 =~ x1 + x2 + x3 + x4 + x5 + x10
f2 =~ x6 + x7 + x8 + x9 + x10 + x2
f3 =~ x11 + x12 + x13 + x14 + x15 + x10 + x9 + x6
f3 ~~ f1 + f2
f1 ~~ f2

'
lrt_5<-sem(model = m_5, data=mydata, meanstructure=FALSE, likelihood = "wishart", estimator = "ML")



m_6<-'  

f1 =~ x1 + x2 + x3 + x4 + x5 + x10
f2 =~ x6 + x7 + x8 + x9 + x10 + x2
f3 =~ x11 + x12 + x13 + x14 + x15 + x10 + x9 + x6 + x8
f3 ~~ f1 + f2
f1 ~~ f2

'
lrt_6<-sem(model = m_6, data=mydata, meanstructure=FALSE, likelihood = "wishart", estimator = "ML")



m_7<-'  

f1 =~ x1 + x2 + x3 + x4 + x5 + x10
f2 =~ x6 + x7 + x8 + x9 + x10 + x2
f3 =~ x11 + x12 + x13 + x14 + x15 + x10 + x9 + x6 + x8
f3 ~~ f1 + f2
f1 ~~ f2
x6	~~	x10
'
lrt_7<-sem(model = m_7, data=mydata, meanstructure=FALSE, likelihood = "wishart", estimator = "ML")


m_8<-'  

f1 =~ x1 + x2 + x3 + x4 + x5 + x10
f2 =~ x6 + x7 + x8 + x9 + x10 + x2
f3 =~ x11 + x12 + x13 + x14 + x15 + x10 + x9 + x6 + x8
f3 ~~ f1 + f2
f1 ~~ f2
x6	~~	x10
x6	~~	x9

'


lrt_8<-sem(model = m_8, data=mydata, meanstructure=FALSE, likelihood = "wishart", estimator = "ML")


m_9<-'  

f1 =~ x1 + x2 + x3 + x4 + x5 + x10
f2 =~ x6 + x7 + x8 + x9 + x10 + x2
f3 =~ x11 + x12 + x13 + x14 + x15 + x10 + x9 + x6 + x8
f3 ~~ f1 + f2
f1 ~~ f2
x6	~~	x10
x6	~~	x9
x10	~~	x11
'


lrt_9<-sem(model = m_9, data=mydata, meanstructure=FALSE, likelihood = "wishart", estimator = "ML")



m_10<-'  

f1 =~ x1 + x2 + x3 + x4 + x5 + x10
f2 =~ x6 + x7 + x8 + x9 + x10 + x2
f3 =~ x11 + x12 + x13 + x14 + x15 + x10 + x9 + x6 + x8
f3 ~~ f1 + f2
f1 ~~ f2
x6	~~	x10
x6	~~	x9
x10	~~	x11
x2	~~	x9
'

lrt_10<-sem(model = m_10, data=mydata, meanstructure=FALSE, likelihood = "wishart", estimator = "ML")



m_11<-'  

f1 =~ x1 + x2 + x3 + x4 + x5 + x10
f2 =~ x6 + x7 + x8 + x9 + x10 + x2
f3 =~ x11 + x12 + x13 + x14 + x15 + x10 + x9 + x6 + x8
f3 ~~ f1 + f2
f1 ~~ f2
x6	~~	x10
x6	~~	x9
x10	~~	x11
x2	~~	x9
x8	~~	x14
'


lrt_11<-sem(model = m_11, data=mydata, meanstructure=FALSE, likelihood = "wishart", estimator = "ML")


m_12<-'  

f1 =~ x1 + x2 + x3 + x4 + x5 + x10
f2 =~ x6 + x7 + x8 + x9 + x10 + x2
f3 =~ x11 + x12 + x13 + x14 + x15 + x10 + x9 + x6 + x8
f3 ~~ f1 + f2
f1 ~~ f2
x6	~~	x10
x6	~~	x9
x10	~~	x11
x2	~~	x9
x8	~~	x14
x6	~~	x8
'

lrt_12<-sem(model = m_12, data=mydata, meanstructure=FALSE, likelihood = "wishart", estimator = "ML")


lavTestLRT(lrt_0, lrt_1, lrt_2, lrt_3, lrt_4, lrt_5, lrt_6, lrt_7, lrt_8, lrt_9, lrt_10, lrt_11, lrt_12)




##########. The End

######### All results match the manuscript, 12/4/24

